package cn.niit.pm.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;

/**
 * Swagger配置文件
 *
 * @author xiaomi
 */
//开启 OpenApi
@EnableOpenApi
@Configuration
public class SwaggerConfig {
    /*
    * 创建获取API应用
    * */
    @Bean
    public Docket docket(){
        Docket docket = new Docket(DocumentationType.OAS_30);
        docket.apiInfo(apiInfo())
                .select()
                 //扫描的路径包,设置basePackage会将包下的所有被@Api标记类的所有方法作为api
                .apis(RequestHandlerSelectors.basePackage("cn.niit.pm.controller"))
                //指定路径处理PathSelectors.any()代表所有的路径
                .paths(PathSelectors.any()).build();
        return docket;
    }

    /*
    * 配置swagger文档显示的相关内容标识(
    * */
    private ApiInfo apiInfo(){
        Contact contact = new Contact("矜契人事管理系统", "localhost:8081/", "小密的邮箱");
        ApiInfo apiInfo = new ApiInfo(
                "衿契人事管理系统之接口文档",
                "SpringBoot 整合 Swagger3 生成接口文档!",
                "1.0.0",
                "termsOfServiceUrl",
                contact,
                "杨勇大侠许可",
                "localhost:8081/",
                new ArrayList());
        return apiInfo;
    }

}
